﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DrSoftsFrame.Servers;
using System.Configuration;
using DrSoftsFrame.Servers;
using System.Data.SqlClient;

namespace PreeRegisterDAL
{
     public class PacsReportDAL
    {


        /// <summary>
        /// 查询检查处方单号
        /// </summary>
        /// <param name="cpatientcode"></param>
        /// <returns></returns>
        public static string Getbillcode(string cpatientcode)
        {
            try
            {
                MZOpDb mydb = new DrSoftsFrame.Servers.MZOpDb();
                string billcode = "";

                SqlCommand cmd = new SqlCommand();

                cmd.CommandText = "up_getbillcode";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p1 = new SqlParameter("@cpatientcode", SqlDbType.VarChar, 20);
                p1.Direction = ParameterDirection.Input;
                p1.Value = cpatientcode;
                cmd.Parameters.Add(p1);

                DataSet ds = mydb.ExecuteSqlCmdFillDs(cmd);

                if (ds == null || ds.Tables.Count < 1)
                {
                    return billcode;
                }
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    billcode += "'" + dr["cBillCode"].ToString() + "',";
                }
                billcode = billcode.Substring(0, billcode.Length - 1);
                return billcode;

            }
            catch (Exception err)
            {

                throw;
            }
        }
      
         
        /// <summary>
        /// 查询检查报告列表
        /// </summary>
        /// <param name="cpatientcode"></param>
        /// <returns></returns>
         public static DataSet GetPacsReportList(string billcode)
        {
            try
            {
                string sqlstr = string.Format(@"SELECT HISExamNO AS  ApplyNo,PARTOFCHECK AS ReportTypeName,MODALITY AS TestSample,PATIENTID AS OrderNo,CHECKDATE AS cjgsj,ReportID AS MainID
                                                from PACSREPORT
                                                where HISExamNO in ({0})
                                                 order by cjgsj desc  ", billcode);
                DrSoftsFrame.Servers.StuffDb mydb = new StuffDb();
                DataSet ds = mydb.ExecuteSelect(sqlstr);
                
                if (ds == null || ds.Tables.Count < 1)
                {
                    return null;
                }
                ds.Tables[0].TableName = "PACSREPORT";
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询检查报告明细
        /// </summary>
        /// <param name="cpatientcode"></param>
        /// <returns></returns>
        public static DataSet GetPacsReportDetail(string mainid)
        {
            try
            {
                string sqlstr = string.Format(@"SELECT ReportID AS mainid,ENROLDOCTOR AS SectionOffice,PATNAME AS Name,MODALITY AS TestSample,CHECKDATE AS jysj,
TITLEONE,CONTENTONE,TITLETWO,CONTENTTWO,TITLETHREE,CONTENTTHREE,TITLEFOUR,CONTENTFOUR,HISExamNO AS ApplyNo FROM dbo.PACSREPORT   WHERE ReportID={0} ", mainid);
                DrSoftsFrame.Servers.StuffDb mydb = new StuffDb();
                DataSet ds = mydb.ExecuteSelect(sqlstr);
                if (ds == null ||  ds.Tables[0].Rows.Count < 1)
                {
                    return null;
                }
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }

    }
}
